/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-15
 * Time: 18:28
 */
class SingletonLazy1 {
    //杜绝在线程1读取时，而线程2在修改，会产生内存可见性问题因此加上volatile
    //volatile最重要的作用是解决指令重排序的问题
    private static volatile SingletonLazy1 instance = null;
    private static Object locker = new Object();
    public static SingletonLazy1 getInstance() {
        //同时还有双重if的问题
        if(instance == null) {
            synchronized (locker) {
                if (instance == null) {
                    instance = new SingletonLazy1();
                }
            }
        }
        return instance;
    }
}
public class Demo39 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {

        });
    }
}
